package com.cjm.one.security.config;

import com.cjm.one.security.authenticationProvider.EmailCodeAuthenticationProvider;
import com.cjm.one.security.authenticationProvider.EmailPasswordAuthenticationProvider;
import com.cjm.one.security.authenticationProvider.MobileCodeAuthenticationProvider;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.userdetails.UserDetailsService;

@Configuration
public class AuthProviderConfig {

    @Bean
    public EmailCodeAuthenticationProvider emailCodeAuthenticationProvider(
        @Qualifier("appUserDetailsService") UserDetailsService userDetailsService
    ) {
        EmailCodeAuthenticationProvider provider = new EmailCodeAuthenticationProvider();
        provider.setUserDetailsService(userDetailsService);
        return provider;
    }

    @Bean
    public MobileCodeAuthenticationProvider mobileCodeAuthenticationProvider(
        @Qualifier("appUserDetailsService") UserDetailsService userDetailsService
    ) {
        MobileCodeAuthenticationProvider provider = new MobileCodeAuthenticationProvider();
        provider.setUserDetailsService(userDetailsService);
        return provider;
    }

    @Bean
    public EmailPasswordAuthenticationProvider emailPasswordAuthenticationProvider(
        @Qualifier("appUserDetailsService") UserDetailsService userDetailsService
    ) {
        EmailPasswordAuthenticationProvider provider = new EmailPasswordAuthenticationProvider();
        provider.setUserDetailsService(userDetailsService);
        return provider;
    }
}